package com.ttai.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.SliderTypes.TextSliderView;
import com.ttai.R;
import com.ttai.ui.base.BaseActivity;
import com.ttai.untils.Constant;

import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UserHomePage extends BaseActivity {
    @Bind(R.id.sl_slider)
    SliderLayout slSlider;
    @Bind(R.id.btn_loginid)
    Button btnLoginid;
    @Bind(R.id.btn_idcard)
    Button btnIdcard;
    @Bind(R.id.btn_userpassword)
    Button btnUserpassword;
    @Bind(R.id.btn_user)
    Button btnUser;

    public String index ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_userhomepage);
        String token = Constant.getToken();
        Log.i("123", "onCreate: token"+token);
        ButterKnife.bind(this);
        addSldieLayout();
//        index = MainActivity.index;
//        if (MainActivity.index == null){
//            System.out.println("11");
//            index = getIntent().getStringExtra("index");
//        }else {
//            index = MainActivity.index;
//        }
//        System.out.println("index"+index);
//        if (index != null){
//            if (index.equals("1")){
//                this.finish();
//                Intent intent = new Intent(this,ZhiWen.class);
//                startActivity(intent);
//            }
//        }
    }

    private void addSldieLayout() {
        HashMap<String,Integer> imgpath = new HashMap<>();
        imgpath.put("态安全宣传1",R.drawable.pic_banner);
        imgpath.put("态安全宣传2",R.drawable.taisercuritybanner_mdpi);
        imgpath.put("态安全宣传3",R.drawable.sercutirybanner_mdpi);

        for (String desc:imgpath.keySet()){
            TextSliderView textSliderView = new TextSliderView(this);
            textSliderView
                    .description(desc)
                    .image(imgpath.get(desc));

            //向SlideLayout控件插入
            slSlider.addSlider(textSliderView);
            slSlider.setPresetIndicator(SliderLayout.PresetIndicators.Right_Bottom);
            slSlider.setPresetTransformer(SliderLayout.Transformer.Accordion);
            slSlider.setDuration(4000);
        }



    }

    @Override
    public void next(View view) {

    }

    @Override
    public void pre(View view) {

    }

    @Override
    public void setComponet() {

    }

    public void onResume() {
        super.onResume();
        if (MainActivity.index == null){
            System.out.println("11");
            index = getIntent().getStringExtra("index");
        }else {
            index = MainActivity.index;
        }
        System.out.println("index"+index);
        if (index != null){
            if (index.equals("1")){
                this.finish();
                Intent intent = new Intent(this,ZhiWen.class);
                startActivity(intent);
            }
        }
    }

    @OnClick({R.id.btn_loginid, R.id.btn_idcard, R.id.btn_userpassword, R.id.btn_user})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_loginid:
                Intent intent3=new Intent();
                intent3.putExtra("value","idcard");
                intent3.setClass(UserHomePage.this,ZhiWen.class);
                startActivity(intent3);
                break;
            case R.id.btn_idcard:
                Intent intent1=new Intent();
                intent1.setClass(UserHomePage.this,VerifyModeModel.class);
                startActivity(intent1);
                break;
            case R.id.btn_userpassword:
                Intent intent2=new Intent();
                intent2.putExtra("value","userpassword");
                intent2.setClass(UserHomePage.this,ZhiWen.class);
                startActivity(intent2);
                break;
            case R.id.btn_user:
                finish();
                Intent intent4=new Intent();
                intent4.setClass(UserHomePage.this,User.class);
                startActivity(intent4);
                break;
        }
    }
}
